//
//  DoubleViewController.m
//  NewUIPickerView
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "DoubleViewController.h"

@interface DoubleViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>


@property (nonatomic,strong) NSArray *leftList;
@property (nonatomic,strong) NSArray *rightList;

@end

@implementation DoubleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.UIPickerView.dataSource = self;
    self.UIPickerView.delegate = self;
    
    self.leftList = @[@"你是",@"他是",@"我是"];
    self.rightList = @[@"小明",@"小华",@"小红"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPresser:(id)sender
{
    int sel1 = [self.UIPickerView selectedRowInComponent:0];
    int sel2 = [self.UIPickerView selectedRowInComponent:1];
    
    self.UILable.text = [NSString stringWithFormat:@"%@%@",self.leftList[sel1],self.rightList[sel2]];
}

//有几列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;//有两列
}
//第几列有几行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0)
    {
        return self.leftList.count;
    }
    else
    {
        return self.rightList.count;
    }
}

//第几行第几列里是什么内容
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0)
    {
        return self.leftList[row];
    }
    else
    {
        return self.rightList[row];
    }
    
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0)
    {
        NSLog(@"当前你选择了%@",self.leftList[row]);
    }else
    {
        NSLog(@"当前你选择了%@",self.rightList[row]);
    }
}



@end
